<?php
    /**
     * Created by PhpStorm.
     * User: huangzhongwei
     * Date: 2018/10/23
     * Time: 15:26
     */

    namespace app\common\model;


    use think\Model;

    class Account extends Model
    {
        protected $table = "account";
        protected $autoWriteTimestamp = true;

        protected $json = ['userinfo'];

        public static function getByOpenID($openid)
        {
            $user = self::where('openid', '=', $openid)
                        ->find();
            return $user;
        }

        public static function getPhone()
        {

        }


        public static function getRunningman($page, $size)
        {
            $result = self::where('is_runningman', 1)->withCount(['universityOrder'=>function($query){
                $query->where('state',5);
            }])->paginate($size, false, ['page' => $page]);
            return $result;
        }


        public function universityOrder()
        {
            return $this->hasMany('Order','order_account_id');
        }


    }